{% extends 'base.html' %}

{% block title %}{{ title }} - EasyTesting{% endblock %}

{% block header %}{{ title }}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-body p-4">
                <form method="post">
                    {% csrf_token %}

                    <div class="mb-4">
                        <label for="{{ form.name.id_for_label }}" class="form-label fw-medium">测试套件名称</label>
                        {{ form.name.errors }}
                        <input type="text" class="form-control form-control-lg" id="{{ form.name.id_for_label }}" name="{{ form.name.html_name }}" value="{{ form.name.value|default:'' }}" required placeholder="输入测试套件名称">
                        <div class="form-text">测试套件名称</div>
                    </div>

                    <div class="mb-4">
                        <label for="{{ form.project.id_for_label }}" class="form-label fw-medium">项目</label>
                        {{ form.project.errors }}
                        {% if form.project.field.widget.input_type == 'hidden' %}
                            {{ form.project }}
                            <input type="text" class="form-control form-control-lg" value="{{ form.project.value|default:''|stringformat:'s' }}" disabled>
                        {% else %}
                            <select class="form-select" id="{{ form.project.id_for_label }}" name="{{ form.project.html_name }}" required>
                                <option value="">选择项目</option>
                                {% for choice in form.project.field.choices %}
                                    <option value="{{ choice.0 }}" {% if form.project.value|stringformat:"s" == choice.0|stringformat:"s" %}selected{% endif %}>{{ choice.1 }}</option>
                                {% endfor %}
                            </select>
                        {% endif %}
                        <div class="form-text">选择测试套件关联的项目</div>
                    </div>

                    <div class="mb-4">
                        <label for="{{ form.group.id_for_label }}" class="form-label fw-medium">分组</label>
                        {{ form.group.errors }}
                        <select class="form-select" id="{{ form.group.id_for_label }}" name="{{ form.group.html_name }}">
                            <option value="">暂无分组</option>
                            {% for choice in form.group.field.choices %}
                                {% if choice.0 %}
                                    <option value="{{ choice.0 }}" {% if form.group.value|stringformat:"s" == choice.0|stringformat:"s" %}selected{% endif %}>{{ choice.1 }}</option>
                                {% endif %}
                            {% endfor %}
                        </select>
                        <div class="form-text">选择测试套件分组 (可选)</div>
                    </div>

                    <div class="mb-4">
                        <label for="{{ form.description.id_for_label }}" class="form-label fw-medium">描述</label>
                        {{ form.description.errors }}
                        <textarea class="form-control" id="{{ form.description.id_for_label }}" name="{{ form.description.html_name }}" rows="4" placeholder="测试套描述...">{{ form.description.value|default:'' }}</textarea>
                        <div class="form-text">测试套件描述...</div>
                    </div>

                    <div class="alert alert-info">
                        <div class="d-flex">
                            <i class="bi bi-info-circle-fill me-2 fs-5"></i>
                            <div>
                                <strong>Note:</strong> 创建测试套件后，可添加测试用例
                            </div>
                        </div>
                    </div>

                    <div class="d-flex justify-content-between mt-4">
                        <a href="{% if request.GET.project %}{% url 'project_detail' pk=request.GET.project %}{% else %}{% url 'test_suite_list' %}{% endif %}" class="btn btn-outline-secondary">
                            <i class="bi bi-arrow-left"></i> 取消
                        </a>
                        <button type="submit" class="btn btn-primary px-4">
                            <i class="bi bi-check-lg"></i> 保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
